package com.zcc.makingfriend.controller;

import com.zcc.makingfriend.dao.Liked;
import com.zcc.makingfriend.dto.ArticleLikedDto;
import com.zcc.makingfriend.service.ArticleService;
import com.zcc.makingfriend.service.LikedService;
import com.zcc.makingfriend.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zcc
 */
@Api(tags = "点赞管理")
@RestController
@RequestMapping("/liked")
public class LikedController {
    @Autowired
    LikedService likedService;


    @ApiOperation("点赞")
    @PostMapping("/add")
    public Result addLiked(@RequestBody ArticleLikedDto liked) {
        System.out.println(liked);
        int i = likedService.addLiked(liked);
        if (i == -1) {
            return Result.fail("已经点赞");
        }
        if (i != liked.getLikes()) {
            return Result.success(i);
        }
        return Result.fail("点赞失败");
    }

    @ApiOperation("取消点赞")
    @PostMapping("/cancel")
    public Result cancelLiked(@RequestBody ArticleLikedDto like) {
        int i = likedService.cancelLiked(like);
        if (i != like.getLikes()) {
            return Result.success(i);
        }
        return Result.fail("取消点赞失败");
    }
}
